
int calculateBCC(String data) {
  var bcc = 0;
  for (var byte in data.codeUnits) {
    bcc ^= byte;
  }
  return bcc;
}

void main() {
  var jsonStr = '{"from":"","to":"test","cmd":"get_datetime","action":"","id":"'
      '7e85c55153794765867639519995bc59","ret":"ok","content":{"data":"2025-08-14","time":"14:22:28"}}';

  // {"from":"","to":"test","cmd":"get_datetime","action":"","id":"643f65d2bd8943b6bf497d3defa8b4af","ret":"ok","content":{"data":"2025-08-14","time":"14:38:01"},"check":0}
  jsonStr = '{"from":"","cmd":"get_datetime","action":"","content":{"data":"2025-08-14","time":"14:38:01"}}';
  final bcc = calculateBCC(jsonStr);
  print('Calculated BCC: $bcc');
  print('Hex representation: 0x${bcc.toRadixString(16).padLeft(2, '0')}');
}